<?php 
if(!empty($_POST['action']))
{
	$html='<ul class="to_select_list">';
	$field_id=empty($_POST['field_id'])?false:$_POST['field_id']+0;
	switch($_POST['action'])
	{
		case 'view':
			$conn->query('select id,title from pages where templ=\'product_category\'');
			while($category=$conn->fetch())
				$html.='<li onclick="_id_selector.updateList({\'category_id\':\''.$category->id.'\'})">'.$category->title.'</li>';
		break;
		case 'add':
			if($field_id)
			{
				if(empty($_POST['value']))
					$ajax.="dee_corner.quick_message('Значение характеристики не может быть пустым');";
				else
				{
					$value=mysql_real_escape_string($_POST['value']);
					$value_sys=mysql_real_escape_string(getGoodUrl($_POST[empty($_POST['value_sys'])?'value':'value_sys']));
					$conn->query("insert into store_p_charact_values(value,value_sys,field_id)values('$value','$value_sys',$field_id)");
				}
			}
		case 'update':
			if(!empty($_POST['category_id']))
			{
				$category_id=$_POST['category_id']+0;
				
					$conn->query("select f.id,f.name from store_p_charact_fields f, groups g  where  g.type='slbl_characteristics_$category_id' and g.name_sys='main' and f.group_id=g.id ; ");
					while($field=$conn->fetch())
						$html.='<li onclick="_id_selector.updateList({\'field_id\':\''.$field->id.'\'})">'.$field->name.'</li>';				
			}
			elseif($field_id)
			{
				$conn->query('select id,value from store_p_charact_values where field_id='.$field_id);
				while($value=$conn->fetch())
					$html.='<li onclick="_id_selector.select('.$value->id.',\''.$value->value.'\')">'.$value->value.'</li>';
				$html.='<li><br /><input type="text" placeholder="Название" class="_value" /> <input type="text" class="_value_sys" placeholder="Системное" /> <br />'
					.$load->block('buttons',array('text'=>'Добавить','attr'=>'onclick="addCharacteristics(this,'.$field_id.')"'))
				.'</li>';
			}
		break;
	}
	$ajax.='data='.getJSArr(array('html'=>$html.'</ul>','title'=>'Выберите характеристику для страницы'));
}